<template>
	<view class="d-flex flex-column flash-news-container j-sb" style="height:65upx">
		<!-- <view v-for="(item, index) in list" class="d-flex a-center" :key="index" style="height: 31upx;line-height: 33upx;margin: 0;padding: 0;">
			<view class="pointer mr-2"></view>
			<text style="font-weight: 600;" class="font-32">{{ item.title }}</text>
		</view> -->
		
	   <!-- <swiper class="swiper" :indicator-dots="indicatorDots" style="height: 40upx;" :autoplay="autoplay" :interval="interval" :duration="duration" circular='true'>
			<swiper-item v-for="(item, index) in list" :key="index" style="height: 40upx;">
				<view class="d-flex a-center" @click="skipToNewDetail(item)" style="height: 31upx;line-height: 33upx;margin: 0;padding: 0;">
					<view class="pointer mr-2"></view>
					<text style="font-weight: 600;" class="font-32">{{ item.title.substring(0, 20) }}</text>
				</view>
			</swiper-item>
		</swiper> -->
		<text v-for="(item, index) in list" :key="index" style="width: 100%;" @click="skipToNewDetail(item)">
			<view class="pointer mr-2" style="float: left;"></view>
			<text style="float: left;display: block;line-height: 0.1upx;" class="font-32">{{ item.title.substring(0, 20) }}</text>
		</text>
	</view>
</template>

<script>
export default {
	data() {
		return {
			indicatorDots: false,
			autoplay: true,
			interval: 3000,
			duration: 500
		};
	},
	props: {
		list: {
			type: Array,
			default: () => {
				return [];
			}
		}
	},
	methods: {
		skipToNewDetail(item) {
			const newsId = item.contentId;
			const url = item.url;
			uni.navigateTo({
				url: '/pages/index/news-detail/news-detail?id=' + newsId + '&link=' + url
			});
			//加入历史记录
			let list = uni.getStorageSync('history');
			list = list ? JSON.parse(list) : [];
			let index = list.findIndex(v => v.contentId === newsId);
			if (list.length >= 50) {
				list.pop();
			}
			if (index === -1) {
				list.unshift(item);
				uni.setStorageSync('history', JSON.stringify(list));
			} else {
				for (var i = 0; i < list.length; i++) {
					if (list[i].contentId === newsId) {
						list.splice(i, 1); // 如果数据组存在该元素，则把该元素删除
						break;
					}
				}
				list.unshift(item);
				uni.setStorageSync('history', JSON.stringify(list));
			}
		}
	}
};
</script>

<style>
.pointer {
	width: 7upx;
	height: 7upx;
	border-radius: 5upx;
	background-color: #005bac;
}
.flash-news-container {
	/* width: 690upx; */
	height: 40upx;
	padding: 40upx 30upx;
	padding-top:50upx;
	border-bottom:25upx solid #f5f9f8;
	width: 100%;
/* 	box-shadow: 0 2px 0 gray; */
}
</style>
